import { userProfilesAPI } from "@/request/Api"

export default {
    namespaced: true,
    state: {
        userInfo: {
            nickName: '彭于晏',
            coin: 99,
            headImg: require('@/assets/img/service.848ec511.png')
        },
        cartTotal: 99
    },
    mutations: {
        // 修改用户信息
        updateUserInfo(state, payload) {
            state.userInfo = payload.userInfo
            state.cartTotal = payload.cartTotal
        },
        // 初始化用户信息
        initUserInfo(state) {
            state.userInfo = {
                nickName: '彭于晏',
                coin: 99,
                headImg: require('@/assets/img/service.848ec511.png')
            },
                state.cartTotal = 99
        }
    },
    // 获取用户信息
    actions: {
        async asyncUpdateUserInfo(context) {
            let res = await userProfilesAPI()
            //  res.data.data=payload 下一层是userInfo
            context.commit('updateUserInfo', res.data.data)
        }

    }
}